
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:szwf/utils/common_toast.dart';
import './Tag.dart';
import 'dart:async';

// class Index extends StatelessWidget {
//   @override
//   Widget build(BuildContext context) {
//     return
// }

class Index extends StatefulWidget {
  @override
  _IndexState createState() => _IndexState();
}

class _IndexState extends State<Index> {
  String weight = '';
  var _weight = TextEditingController();
  String time = '';
  @override
  void initState() {
    super.initState();
    updataTime();
  }

  updataTime() {
    const timeout = const Duration(seconds: 1);
    // print('currentTime =' + DateTime.now().toString());
    Timer(timeout, () {
      //到时回调
      var nowTime = DateTime.now();
      var span = Duration(hours: 8);
      nowTime = nowTime.add(span);
      // print(nowTime);
      setState(() {
        this.time = nowTime.toString().substring(0, 19);
      });
      // print(nowTime);
      updataTime();
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          // backgroundColor: Colors.white,
          title: Text('苏州正济药业有限公司'),
          actions: <Widget>[
            Container(
              padding: EdgeInsets.fromLTRB(0, 15, 10, 10),
              child: Text('$time',
                  style: TextStyle(
                    fontSize: 20.0,
                    // color: Colors.blue,
                  )),
            )
          ],
        ),
        body: Center(
          child: Container(
            padding: EdgeInsets.all(20),
            child: ListView(
              children: <Widget>[
                Text('称重重量:$weight'),
                Container(
                  height: 300,
                  child: Center(
                    child: Container(
                      child: Stack(
                        children: <Widget>[
                          Center(
                            child: CircleAvatar(
                              //头像半径
                              //89,129,156    89,151,155
                              backgroundColor: Color.fromRGBO(89, 151, 155, 1),
                              radius: 100,
                              //头像图片 -> NetworkImage网络图片，AssetImage项目资源包图片, FileImage本地存储图片
                            ),
                          ),
                          Center(
                            child: CircleAvatar(
                              //头像半径
                              backgroundColor: Colors.white,
                              radius: 86,
                              //头像图片 -> NetworkImage网络图片，AssetImage项目资源包图片, FileImage本地存储图片
                            ),
                          ),
                          Center(
                            child: Column(
                              mainAxisAlignment: MainAxisAlignment.center,
                              children: <Widget>[
                                Container(
                                  width: 50,
                                  child: TextField(
                                    controller: _weight,
                                    onChanged: (value) {
                                      setState(() {
                                        weight = value;
                                      });
                                    },
                                    keyboardType: TextInputType.number,
                                    textAlign: TextAlign.center,
                                    inputFormatters: [
                                      WhitelistingTextInputFormatter(
                                          RegExp("[0-9.]")), //只允许输入小数
                                    ],
                                    // inputFormatters: <TextInputFormatter>[
                                    //   WhitelistingTextInputFormatter.digitsOnly,
                                    // ],
                                  ),
                                ),
                                Container(
                                  padding: EdgeInsets.only(top: 10),
                                  child: Text('t'),
                                ),
                              ],
                            ),
                          ),
                          // Positioned(
                          //   child: Text('1'),
                          // )
                        ],
                      ),
                    ),
                  ),
                ),
                Center(
                    child: Row(
                      crossAxisAlignment: CrossAxisAlignment.center,
                      mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                      children: <Widget>[
//                    Padding(
//                      padding: EdgeInsets.fromLTRB(0, 30, 0, 0),
//                      child: RaisedButton(
//                        child: Text("归零"),
//                        textColor: Colors.white,
//                        onPressed: () => {
//                          setState(() {
//                            this._weight.text = '';
//                          })
//                        },
//                        shape: RoundedRectangleBorder(
//                            borderRadius: BorderRadius.circular(20)),
//                        color: const Color.fromARGB(255, 69, 200, 233),
//                      ),
//                    ),
                        Padding(
                          padding: EdgeInsets.fromLTRB(0, 0, 0, 0),
                          child: Container(
                            width: 120,
                            child: RaisedButton(
                              child: Text("下一步"),
                              textColor: Colors.white,
                              onPressed: () => {
                                if(weight.length == 0) {
                                  CommonToast.showToast('称重量为必选参数!')
                                } else {
                                  Navigator.of(context).push(
                                    new MaterialPageRoute(
                                      builder: (context) {
                                        return Tag();
                                      },
                                      settings: RouteSettings(
                                        arguments: {"weight": weight.toString()},
                                      ), // 传参
                                      fullscreenDialog: true,
                                    ),
                                  )
                                }

                              },
                              color: const Color.fromARGB(255, 76, 160, 245),
                              shape: RoundedRectangleBorder(
                                borderRadius: BorderRadius.circular(20),
                              ),
                            ),
                          ),
                        ),
//                    Padding(
//                      padding: EdgeInsets.fromLTRB(0, 30, 0, 0),
//                      child: RaisedButton(
//                        child: Text("去皮"),
//                        textColor: Colors.white,
//                        onPressed: () => print("普通按钮"),
//                        color: const Color.fromARGB(255, 69, 200, 233),
//                        shape: RoundedRectangleBorder(
//                            borderRadius: BorderRadius.circular(20)),
//                      ),
//                    ),
                      ],
                    ))
              ],
            ),
          ),
        ));
  }
}
